;
var _pageUrl = "/htmlWeb/certiAudit/list";
var pageGrid;
function init() {
    //日期范围限制
    var start = {
        elem: '#start',
        format: 'YYYY-MM-DD',
        // min: laydate.now(), //设定最小日期为当前日期
        max: '2099-06-16', //最大日期
        istime: true,
        istoday: false,
        choose: function(datas){
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    };
    var end = {
        elem: '#end',
        format: 'YYYY-MM-DD',
        max: '2099-06-16',
        event: 'click',
        istime: true,
        istoday: false,
        choose: function(datas){
            start.max = datas; //结束日选好后，充值开始日的最大日期
        }
    };
    laydate(start);
    laydate(end);
    $.post("htmlWeb/certiAudit/getSearchOption", function (data) {
        var _authType = "";
        var _status = "";
        $.each(data.authType, function (index, obj) {
            var opt = obj.split(";");
            _authType += '<option value="' + opt[0] + '">' + opt[1] + '</option>'
        });
        $("#authType").append('<option value=""></option>'+_authType);
       /* if(data.authStatus != undefined){
            $.each(data.authStatus, function (index, obj) {
                var opt = obj.split(";");
                _status += '<option value="' + opt[0] + '">' + opt[1] + '</option>';
            });
            $("#status").append(_status);
        }*/
    });
    $(".conBut").click(function () {
        var o = $("#authSearchForm").serializeSearchForm();
        if(o.start != undefined && o.start != null){
            o.start = date2timestamp(o.start+" 00:00:00");
        }if(o.end != undefined && o.end != null){
            o.end = date2timestamp(o.end+" 23:59:59");
        }
        pageGrid.search(o);
    });
    $("#imgCancel").click(function () {
        $(".roleNew,.layerDele").css({
            display: "none"
        });
    });
}
/**
 * 时间字符串转时间戳
 * datestr: 2017-07-30 19:15:12
 */
var date2timestamp = function (datestr) {
    if(datestr == null) return;
    var timestamp2 = Date.parse(new Date(datestr));
    timestamp2 = timestamp2 / 1000;
    return timestamp2;
}
function pageBar() {
    pageGrid=  $("#pager").createPage({
        url: _pageUrl,
        params:{userId: loginUserId, status: $("#status").val()},
        ajaxBackFn: function (data) {
            var _gridHtml = '';
            $.each(data.rows, function (index, row) {
                _gridHtml += '<tr>' +
                    '<td><p>' + row.id + '</p></td>' +
                    '<td><p>' + row.authTypeName + '</p></td>' +
                    '<td><p>' + row.authLevelName + '</p></td>' +
                    '<td><p>' + row.statusName + '</p></td>' +
                    '<td><p>' + (row.imgUrl == null ? "":'<a href="javascript:void(0);" onclick="viewImg(this)"><img src="'+_imgesByUrl + row.imgUrl + '" width="60px" height="40px"/></a>') + '</p></td>' +
                    '<td><p>' + (row.descn==null?"":row.descn) + '</p></td>' +
                    '<td><p>' + (row.dailishang == null?"":row.dailishang) + '</p></td>' +
                    '<td><p>' + row.createTimeName + '</p></td>' +
                    '<td><p>' + row.statusName + '</p></td>' +
                    '</tr>';
            });
            $("#mineCertificaGrid tr:not(:first)").html("");
            $('#mineCertificaGrid').append(_gridHtml);
        }
    });
}
function viewImg(img) {
    $("#file_img img").attr("src",$(img).find('img').attr("src"));
    $("#file_img").css("width",'656px');
    $("#file_img").css("height",'400px');
    $(".layerDele").css("width",'656px');
    $(".layerDele").css("height",'580px');
    $(".roleNew,.layerDele").css({
        top:($(window).height()-$(".roleNew,.imges").height())/2+$(window).scrollTop()+"px",
        display:"block"
    });
}
$(function () {
    init();
    pageBar();
});